﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ENMAX_ArcGIS.Hardware_Controllers
{
    class SmartTableHardwareController
    {
    }
}

//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Windows;
//using System.Windows.Controls;
//using System.Windows.Data;
//using System.Windows.Documents;
//using System.Windows.Input;
//using System.Windows.Media;
//using System.Windows.Media.Imaging;
//using System.Windows.Navigation;
//using System.Windows.Shapes;
//using System.Windows.Interop;
//using System.ComponentModel;
//using System.Windows.Threading;
//using System.Timers;
//using System.Windows.Ink;
//using libSMARTMultiTouch;
//using System.Runtime.InteropServices;

//namespace eHomeFloorPlan
//{
//    unsafe class SMARTTableHardwareController
//    {
//        [DllImport("pgrflycapture.dll")]
//        public static extern int flycaptureCreateContext(int* flyCaptureContext);

//        [DllImport("pgrflycapture.dll")]
//        public static extern int flycaptureInitialize(int flyCaptureContext, int cameraIndex);

//        private eHomeMainWindow mainWindow = null;
//        private eHomeWindow eHomeWindow;

//        private static SMARTTableHardwareController mainWindowController = null; // This version of the Controller is for the Main Window
//        private static SMARTTableHardwareController dialogBoxController = null;  // This version of the Controller is for Dialog Box windows
//        MultitouchHandler mainWindowMTHandler;
//        MultitouchHandler dialogBoxMTHandler;
//        TouchReceiver mainWindowTouchReceiver;
//        TouchReceiver dialogBoxTouchReceiver;

//        MultiTouchLib multiTouchLib;

//        int firstTouchID = -1;
//        int secondTouchID = -1;

//        Point firstPosition = new Point();
//        Point secondPosition = new Point();
        
//        double prevDistance = 0.0;
//        double currentDistance = 0.0;

//        public SMARTTableHardwareController(eHomeMainWindow mainWindow, eHomeWindow eHomeWindow)
//        {
//            locatePGRCamera();

//            this.mainWindow = mainWindow;
//            this.eHomeWindow = eHomeWindow;

//            // The SMARTTable SDK requires the presence of these directories. If they are not present, then the SDK will throw an exception
//            System.IO.Directory.CreateDirectory("Complements");
//            System.IO.Directory.CreateDirectory("Logs");

//            mainWindowMTHandler = new MultitouchHandler(mainWindow, mainWindow.mainCanvas);
//            mainWindowTouchReceiver = new TouchReceiver(mainWindowMTHandler);

//            mainWindowMTHandler.ContactDown += new TouchEventHandler(multiTouchHandler_ContactDown);
//            mainWindowMTHandler.ContactMove += new TouchEventHandler(multiTouchHandler_ContactMove);
//            mainWindowMTHandler.ContactUp += new TouchEventHandler(multiTouchHandler_ContactUp);
//        }

//        public SMARTTableHardwareController(Window dialogBox, Canvas canvas)
//        {
//            dialogBoxMTHandler = new MultitouchHandler(dialogBox, canvas);
//            dialogBoxTouchReceiver = new TouchReceiver(dialogBoxMTHandler);
//        }

//        #region Static Methods
//        public static void createInstance(eHomeMainWindow mainWindow, eHomeWindow eHomeWindow)
//        {
//            if (mainWindowController == null)
//                mainWindowController = new SMARTTableHardwareController(mainWindow, eHomeWindow);
//        }

//        public static void createInstance(Window dialogBox, Canvas canvas)
//        {
//            if (dialogBoxController == null)
//            {
//                dialogBoxController = new SMARTTableHardwareController(dialogBox, canvas);
//            }
//        }

//        public static SMARTTableHardwareController getMainWindowInstance()
//        {
//            return mainWindowController;
//        }

//        public static SMARTTableHardwareController getDialogInstance()
//        {
//            return dialogBoxController;
//        }

//        public static void resetDialogBoxInstance()
//        {
//            dialogBoxController = null;
//        }
//        #endregion

//        #region Hardware Detection
//        public void locatePGRCamera()
//        {
//            int flyCaptureContext;
//            int returnValue = flycaptureCreateContext(&flyCaptureContext);
			
//            if (returnValue	!= 0 )
//            {
//                throw new Exception("PGR Camera could not be located");
//            }

//            returnValue = flycaptureInitialize( flyCaptureContext, 0);
            
//            if (returnValue != 0)
//            {
//                throw new Exception("PGR Camera could not be located");
//            }
//        }
//        #endregion

//        #region Touch Events
//        private void multiTouchHandler_ContactDown(object sender, int ID, Point p, bool inCentre)
//        {            
//            if (firstTouchID == -1)
//            {   
//                firstTouchID = ID;
//                firstPosition.X = p.X;
//                firstPosition.Y = p.Y;
                
//                Core.InputDevices.Mouse.Instance.Location = new System.Drawing.Point((int)p.X, (int)p.Y + 15);
//                Core.InputDevices.Mouse.LeftDown();
//            }

//            else if (p.X <= firstPosition.X + 30 || p.X >= firstPosition.X - 30)
//            {
//                Core.InputDevices.Mouse.Instance.RightClick();
//            }

//            if(firstTouchID != -1 && secondTouchID == -1)
//            {
//                secondTouchID = ID;
//                secondPosition.X = p.X;
//                secondPosition.Y = p.Y;
//            }
//        }

//        private void multiTouchHandler_ContactMove(object sender, int ID, Point p, bool inCentre)
//        {
//            if (ID == firstTouchID)
//            {
//                Core.InputDevices.Mouse.Instance.Location = new System.Drawing.Point((int)p.X, (int)p.Y + 15);
//                firstPosition.X = p.X;
//                firstPosition.Y = p.Y;
//            }

//            else
//            {
//                Core.InputDevices.Mouse.LeftUp();
//                secondPosition.X = p.X;
//                secondPosition.Y = p.Y;

//                if (mainWindow != null)
//                {
//                    prevDistance = currentDistance;
//                    currentDistance = MathLib.getInstance().calcDistanceBetweenPoints(firstPosition, secondPosition);

//                    if (MathLib.getInstance().calcDifferenceBetweenValues(currentDistance, prevDistance) > 5)
//                    {                        
//                        multiTouchLib.handleImageResize(currentDistance, prevDistance);
//                    }
//                }
//            }
//        }

//        private void multiTouchHandler_ContactUp(object sender, int ID, Point p, bool inCentre)
//        {
//            if (ID == firstTouchID)
//            {
//                Core.InputDevices.Mouse.LeftUp();
//                firstTouchID = -1;
//            }

//            if (ID == secondTouchID)
//            {
//                secondTouchID = -1;
//            }
//        }
//        #endregion
        
//        #region Public Helper Methods
//        public void setUpMultiTouchLib()
//        {
//            multiTouchLib = new MultiTouchLib(eHomeWindow.FloorPlanImage, eHomeWindow.FloorPlan, eHomeWindow.DeviceList, eHomeWindow.ContainerList, eHomeWindow.SensorList, eHomeWindow.FloorPlanStagingArea);
//        }

//        public DraggableObjectBorder createNewDraggableObjectBorder(Image image, bool draggable, bool multiTouchRotate, bool singleTouchRotate, bool pickUpAndDropAnimation, bool tossable)
//        {
//            DraggableObjectBorder border = new DraggableObjectBorder();
//            border.Child = image;
//            border.Tag = image.Tag;
//            border.Width = image.Width;
//            border.Height = image.Height;
//            border.MinWidth = image.MinWidth;
//            border.MinHeight = image.MinHeight;
//            border.MaxWidth = image.MaxWidth;
//            border.MaxHeight = image.MaxHeight;
//            border.IsRotatedOnDrag = multiTouchRotate;
//            border.IsResizedOnTouch = pickUpAndDropAnimation;
//            border.IsTossable = tossable;
//            border.CanMove = draggable;
//            border.CanRotate = singleTouchRotate;
//            border.MoveToTopOnTouch = false;
//            border.DefaultPointerType = PointerType.PT_NONE;
//            return border;
//        }
//        #endregion
//    }
//}